#pragma once

#include "EZRPC_ServerPool.h"
#include "EZWebsocketServer.h"
#include "ExClosure.h"
#include "EZRPC_Ctl.h"
#include "transport/EZNoTlsTransport.h"

class EZRPC_Server
{
public:
	EZRPC_Server();
	~EZRPC_Server();

	bool register_server(google::protobuf::Service* sr) { return pool_.register_server(sr); }

	void unregister_server(google::protobuf::Service* sr){ pool_.unregister_server(sr); }

	bool start(int port);

	void stop() { server_.stop(); }
private:
	void done_handle(int32_t reqid,google::protobuf::Message* response
		, EZRPC_Ctl* ctl, EZWebsocket::EZWebsocketConPtr stream);
private:
	void message_callback(const EZWebsocket::EZWebsocketConPtr& stream,
		const EZWebsocket::EZWebsocketMsg& msg);
private:
	EZRPC_ServerPool  pool_;
	EZWebsocket::EZWebsocketServer<EZNoTlsTransport>		 server_;
};

